package top.sjydzq.www.controller.Mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import top.sjydzq.www.service.StarService;

@Controller
public class StarController {
    @Autowired
    private StarService starService;

    @RequestMapping("/star")
    public String star(int pid, int uid, Model model) {
        String result;

        if (starService.selectCountById(pid, uid) == 0) {
            if (starService.addStar(pid, uid)) {
                result = "关注成功！";
            } else {
                result = "关注失败！";
            }
        } else {
            result = "已关注，不能重复关注！";
        }

        model.addAttribute("result", result);

        return "Mall/Modal/starResult";
    }
}
